var React = require('react');

var TodoItem = require('./TodoItem.jsx')

let ids = 0;
class TodoList extends React.Component {
    constructor(props) {
        super(props);
        this.state = { db: [{id:0,title:'aaa'}] };
    }
    onAdd(val) {
        this.state.db.push({
            title:val,
            id:++ids
        })
    }
    onDestroy(item){
        console.log(item);
        alert('aaa');
    }
    render() {
        let todos = this.state.db.map((item, index) => {
            return <TodoItem
                key={item.id}
                title={item.title}
                onDestroy={this.onDestroy.bind(this, item)}
            />
        });

        return (
            <div className="main">
                <ul className="todo-list">
                    {todos}
                </ul>
            </div>
        )
    }
}


module.exports = TodoList;